<?php
class LogLib {                    //c:CONST                     G:GET
	static public $err = array('C_N_D'=>1,'DB'=>2,'APP'=>3,'G_PARA'=>4,'FILE'=>5,'SYSTEM'=>6);

	static function accessWrite($message , $module = 0 ) {
		if(ACCESS_LOG == 'DB'){
			$db = getDb(DEF_DB_CONN);
			$rs = $db->checkTable('action_log');
			if(!$rs)
				stop('access_log table is null','DB');
			
			$ip = get_client_ip();
			$time = date("Y-m-d H:i:s");
			$y_m_d = date("Y-m-d");
			$day = date("d");
			$year = date("Y");
			$month = date("m");
				
			$uid = 0;
			
			if($module)
				$module = self::$err[$module];
			
			$data = array(
					'uid'=>$uid,
					'ctrl'=>CTRL,
					'ac'=>AC,
					'ip'=>$ip,
					'msg'=>$message,
					'module'=>$module,
					'access_type'=>ACCESS_TYPE,
					'year'=>$year,
					'month'=>$month,
					'day'=>$day,
					'y_m_d'=>$y_m_d,
					'ctime'=>$time,
			);
			
			$db->add($data,'action_log');
			
		}elseif(ACCESS_LOG == 'FILE'){
			
		}
	}
	
	static function errorWrite($message , $module = 0) {
		if(ERROR_LOG == 'DB'){
			$db = getDb(DEF_DB_CONN);
			$rs = $db->checkTable('error_log');
			if(!$rs)
				stop('error_log table is null','DB');
			
			$ip = get_client_ip();
			$time = date("Y-m-d H:i:s");
			$y_m_d = date("Y-m-d");
			$day = date("d");
			$year = date("Y");
			$month = date("m");
			
			$uid = 0;

			$ctrl = "";
			if(defined('CTRL'))
				$ctrl = CTRL;
			
			$ac = "";
			if(defined('AC'))
				$ac = AC;
			
			if($module){
				if(isset(self::$err[$module]))
					$module = self::$err[$module];
				else
					$module = 1;
			}
			$data = array(
					'uid'=>$uid,
					'ctrl'=>$ctrl,
					'ac'=>$ac,
					'ip'=>$ip,
					'msg'=>$message,
					'module'=>$module,
					'access_type'=>ACCESS_TYPE,
					'year'=>$year,
					'month'=>$month,
					'day'=>$day,
					'y_m_d'=>$y_m_d,
					'ctime'=>$time,
			);
				
			$db->add($data,'error_log');
			
			
			
		}elseif(ACCESS_LOG == 'FILE'){
				
		}
		
	}
	
}
